import {
    AsyncStorage
} from 'react-native';

export default class DeviceStorage {

    static get(key) {
        return AsyncStorage.getItem(key).then((value) => {
            return value;
        });
    }

    static save(key, value) {
        return AsyncStorage.setItem(key, JSON.stringify(value));
    }

    static update(key, value) {
        return DeviceStorage.get(key).then((item) => {
            value = typeof value === 'string' ? value : Object.assign({}, item, value);
            return AsyncStorage.setItem(key, JSON.stringify(value));
        });
    }

    static getUser() {
        const data = this.get("user");
        return data;
        // if (data) {
        //     return {name: data['name'], token: data['token']};
        // } else {
        //     return ({name: 'asd', token: 'ttt'})
        // }

    }

    static delete(key) {
        return AsyncStorage.removeItem(key);
    }
}